package com.by.controller;

import com.by.constant.MessageConstant;
import com.by.entity.Result;
import com.by.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.*;


@RestController
@RequestMapping("/report")
public class ReportController {

    @Autowired
    private ReportService reportService;

    /**
     * @Description: 查询会员报表信息
     * @Param: * @param
     * @return: com.by.entity.Result
     * @Author: GP
     * @Date: 2024/1/16
     */
    @RequestMapping("/getMemberReport")
    public Result getMemberReport() {
        try {
            Map<String, Object> map = reportService.getMemberReport();
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS, map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }

    /**
    * @Description: 获取套餐报表信息
            * @Param: * @param
            * @return: com.by.entity.Result
            * @Author: GP
            * @Date: 2024/1/16
            */
    @RequestMapping("/getSetmealReport")
    public Result getSetmealReport() {
        try {
            List<Map<String, Object>> mapList = reportService.getSetmealReport();
            List<String> setmealNames = new ArrayList<>();
            for (Map<String, Object> map: mapList) {
                setmealNames.add((String)map.get("name"));
            }

            Map<String, Object> map = new HashMap<>();
            map.put("setmealNames", setmealNames);
            map.put("setmealCount",mapList);
            return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS, map);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
        }

    }


}
